package com.spring.security.web.service.impl;

import javax.annotation.Resource;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;

import org.springframework.stereotype.Service;

import com.spring.activemq.model.BaseJms;
import com.spring.nbrbt.tools.otherutil.LogUtils;
import com.spring.security.web.dao.JedisCache;
import com.spring.security.web.model.Log;
import com.spring.security.web.service.MessageComsumer;

@Service
public class MessageComsumerImpl implements MessageComsumer{
	
	@Resource
	private JedisCache jedisCache;

	@Override
	public void emailComsumer(Message message) throws JMSException{
		Log log = new Log();
		if(message instanceof ObjectMessage){
            ObjectMessage objectMessage=(ObjectMessage) message;
	        try {
	            log=(Log) objectMessage.getObject();
	            LogUtils.sendExceptionMail(log);
	        } catch (JMSException e) {
	            e.printStackTrace();
	        }
		}
	}

	@Override
	public void objectComsumer(Message message) throws JMSException {
		BaseJms baseJms = new BaseJms();
		if(message instanceof ObjectMessage){
            ObjectMessage objectMessage=(ObjectMessage) message;
	        try {
	        	baseJms=(BaseJms) objectMessage.getObject();
	        	System.out.println("objectjms receive------->"+baseJms.toString());
	        } catch (JMSException e) {
	            e.printStackTrace();
	        }
		}
	}
}
